<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <cpn ></cpn>

</div>
<template id="cpn">
    <div>
        <h2>儿子模块</h2>
        <ccpn></ccpn>
    </div>
</template>
<template id="ccpn">
    <div>
        <h2>ccpn孙子模块</h2>
        <button v-on:click="btnClick">孙子组件按钮</button>
    </div>
</template>
<script src="../js/vue.js"></script>
<script>

    const cpn = {
        template: "#cpn",
        data() {
            return {
                name: '儿子模块name'
            }
        },
        components: {
            ccpn: {
                template: "#ccpn",
                data() {
                    return {
                        name: '孙子模块name'
                    }
                },
                methods: {
                    btnClick() {
                        // 通过parent使用父组件的相关东西, 父组件为vuecomponent
                        console.log(this.$parent);
                        console.log(this.$parent.name);

                        // 直接访问跟Vue实例
                        console.log(this.$root.msg);
                    }
                }
            }
        }
    }
    const app = new Vue({
        el: "#app",
        data: {
            msg: "hello"
        },
        components: {
            cpn: cpn
        },
    })
</script>
</body>
</html>